package com.thomas.sharing.mybatis.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.thomas.sharing.mybatis.model.Displacement;
import com.thomas.sharing.mybatis.model.PriceResult;
import com.thomas.sharing.mybatis.model.Product;
import com.thomas.sharing.mybatis.request.PriceRequest;

@Component
@Qualifier("carDaoMybatis")
public class CarDaoMybatis implements CarDao{
	
	@Autowired
	private SqlSession sqlSession;
	
	public List<Product> getProductsByBrands(List<String> brands){
		Map<String, Object> parameterMap = new HashMap<String, Object>();
		parameterMap.put("brandList", brands);
		return this.sqlSession.selectList("car.getProductsByBrands", parameterMap);
	}
	
	public List<Displacement> getDisplacementByBrandsAndProducts(List<String> brands, List<String> products){
		Map<String, Object> parameterMap = new HashMap<String, Object>();
		parameterMap.put("brandList", brands);
		parameterMap.put("productList", products);
		return this.sqlSession.selectList("car.getDisplacementByBrandsAndProducts", parameterMap);
	}

	public List<PriceResult> getPrices(PriceRequest priceRequest) {
		Map<String, Object> parameterMap = new HashMap<String, Object>();
		parameterMap.put("brandList", priceRequest.getBrands());
		parameterMap.put("productList", priceRequest.getProducts());
		parameterMap.put("displacementList", priceRequest.getDisplacements());
		return this.sqlSession.selectList("car.getPrices", parameterMap);
	}
}
